﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;
using NUnit.Framework;
using Sripirom.Pattern.UnitTest.Core.UnitOfWork;
using Sripirom.Pattern.UnitTest.Model.TestCases;
using Sripirom.Pattern.UnitTest.Repository.Configuration;
using Sripirom.Pattern.UnitTest.Repository.Configuration.Repositories;
namespace Sripirom.Pattern.UnitTest.Simple.Test
{
    [TestFixture]
    public class XmlElementMappingTest
    {

        [Test]
        public void Test_Mapping_UnitTestCategory_UnitTestClass()
        {
            //XmlUnitOfWork.Default = new XmlUnitOfWork();
            IUnitOfWork uow = new XmlUnitOfWork();
            IUnitTestCategoryRepository repo = new UnitTestCategoryRepository(uow);
            UnitTestCategory category = repo.FindBy("Cat1");

            Assert.IsNotNull(category);
            Assert.AreEqual(1, category.TestClasses.Count());
            Assert.AreEqual(2, category.TestClasses.FirstOrDefault().TestFunctions.Count());
            Assert.AreEqual(1, category.TestClasses.FirstOrDefault().TestFunctions.FirstOrDefault().TestCases.Count());
            UnitTestCase tCase = category.TestClasses.FirstOrDefault().TestFunctions.FirstOrDefault().TestCases.FirstOrDefault();
            Assert.AreEqual(2, tCase.TestParameters.Count());

        }

        [Test]
        public void Test_AddElement_UnitTestCategory_UnitTestClass()
        {
            IUnitOfWork uow = new XmlUnitOfWork();
            IUnitTestCategoryRepository repo = new UnitTestCategoryRepository(uow);
            UnitTestCategory category = repo.FindBy("Cat1");
            category.Id = "Cat2";

            repo.Add(category);

            uow.Commit();

            category = repo.FindBy("Cat2");
            Assert.IsNotNull(category);
            Assert.AreEqual(1, category.TestClasses.Count());
           
        }



    }
}
